﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using Boiling.BizFacade;

namespace Boiling.Web
{
    public partial class Blog : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            string m_blogID;

            if (Session.Contents["userID"] == null) Response.Redirect("default.aspx"); 
            m_blogID = Request.QueryString["bid"];
            c_Diary m_blog = (new BlogManager()).GetDiarydataByNo(m_blogID);
            if (m_blog != null)
            {
                if (Session.Contents["myTitle"] == null)
                {
                    Session.Add("myTitle", m_blog.diaryTitle);
                    Session.Add("myBlog", m_blog);
                    Session.Add("myContent", m_blog.diartContent);
                }
                else
                {
                    Session.Contents["myTitle"] = m_blog.diaryTitle;
                    Session.Contents["myBlog"] =  m_blog;
                    Session.Contents["myContent"] = m_blog.diartContent;
                }
            }
            else
            {
            };

        }
        public void LinkButton_Click(Object sender, EventArgs e)
        {

            if (Session.Contents["userID"] != null)
            {
                Session.Remove("userID");
            }
            Response.Redirect("Default.aspx");
        }
        public void Delete_Click(Object sender, EventArgs e)
        {
            c_Diary blog = (c_Diary)Session.Contents["myBlog"];
            if ((string)Session.Contents["userID"] == blog.diaryOwnerID)
            {
                new BlogManager().DeleteDiaryByNo(blog.diaryID);
                Response.Redirect("myBlog.aspx");
            }
            else
            {
                Response.Redirect("Error.aspx");
            }
        }
        public void Modify_Click(Object sender, EventArgs e)
        {
            c_Diary blog = (c_Diary)Session.Contents["myBlog"];
            if ((string)Session.Contents["userID"] == blog.diaryOwnerID)
            {
                Response.Redirect("ModifyBlog.aspx");
            }
            else
            {
                Response.Redirect("Error.aspx");
            }
        }
    }
}
